/*
 * This file is part of ksPlatform
 * 
 * Copyright (c) 2014-2015
 * 
 * This file is dual-licensed under the AGPLv3 (http://www.gnu.org/licenses/agpl-3.0.html) 
 * 
 * If you are unsure which license is appropriate for your use, please contact the sales department
 * at 97041437@qq.com.
 */

package cn.com.ksplatform.modules.system.auth.menumanager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.ksplatform.base.BaseController;
import cn.com.ksplatform.base.Return;
import cn.com.ksplatform.base.SimpleReturn;
import cn.com.ksplatform.base.page.PageInfoModel;
import cn.com.ksplatform.base.service.BaseService;
import cn.com.ksplatform.modules.system.auth.menumanager.model.PlatMenu;
import cn.com.ksplatform.modules.system.auth.menumanager.service.PlatMenuService;

/**
 * ClassName:PlatMenuController <br/>
 * Date: 2015年5月11日 下午8:40:43 <br/>
 * 
 * @author Mr.Luoxing
 * @version 1.0
 */
@Controller
@RequestMapping("/modules/system/menu")
public class PlatMenuController extends BaseController {

	PlatMenuService menuService;

	@Resource(name = "system.modules.system.PlatMenuService")
	@Override
	public void setBaseService(BaseService baseService) {
		menuService = (PlatMenuService) baseService;
		super.setBaseService(baseService);
	}

	@RequestMapping("page")
	@ResponseBody
	public PageInfoModel queryPage() throws Exception {
		return super.queryPage(PlatMenu.class);
	}

	@RequestMapping("sou")
	@ResponseBody
	public Return sou(PlatMenu menu) throws Exception {
		return SimpleReturn.success("操作成功",menuService.saveOrUpdate(menu));
	}

	@RequestMapping("save")
	@ResponseBody
	public Return save(PlatMenu menu) throws Exception {
		return SimpleReturn.success("操作成功",menuService.save(menu));
	}

	@RequestMapping("update")
	@ResponseBody
	public Return update(PlatMenu menu) throws Exception {
		return SimpleReturn.success("操作成功",menuService.update(menu));
	}

	@RequestMapping("delete")
	@ResponseBody
	public Return delete(PlatMenu menu) throws Exception {
		return SimpleReturn.success("操作成功",menuService.delete(menu));
	}

	@RequestMapping("get/{id}")
	@ResponseBody
	public Return load(@PathVariable String id) {
		return super.load(PlatMenu.class, id);
	}

	@RequestMapping("findAll")
	@ResponseBody
	public Return findAll() throws Exception {
		return super.findAll(PlatMenu.class);
	}
	
	@RequestMapping("tree")
	@ResponseBody
	public List<PlatMenu> tree() throws Exception {
		@SuppressWarnings("unchecked")
		List<PlatMenu> list = menuService.getAllMenus();
		return list;
	}
}
